package com.neusoft.springboot04.common;

import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

@RestControllerAdvice
public class MyExceptionHander {

    @ExceptionHandler(value = MyException.class)
    public Object throwMyExceptionHander(HttpServletRequest request,Exception ex)
    {
        System.out.println("自定义异常处理");
        Map<String,Object> map = new HashMap<>();
        map.put("code",10000);
        map.put("msg",ex.getMessage());
        map.put("url",request.getRequestURI().toString());
        map.put("data","参数传递有问题，，仔细查找api文档！！！");
        return map;
    }


    @ExceptionHandler(value = Exception.class)
    public Object throwGloabExceptionHander(HttpServletRequest request,Exception ex)
    {

        Map<String,Object> map = new HashMap<>();
        map.put("code",10001);
        map.put("msg",ex.getMessage());
        map.put("url",request.getRequestURI().toString());
        map.put("data","后台服务器又问题！！！！");
        return map;
    }
}


